/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2023-04-18
 * Time: 22:49
 */
public class balancedStringSplit {
    // 贪心算法
    // 只要出现了相同个数的 R 和 L 就 ++
    public int balancedStringSplit(String s) {
        int count = 0;
        int temp = 0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == 'R'){
                temp++;
            }else{
                temp--;
            }
            if(temp == 0){
                count++;
            }
        }
        return count;
    }
}
